package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class JDBCDemo12 {
    public static void main(String[] args) {
        Scanner  scan = new Scanner(System.in);
        System.out.println("请输入用户名:");
        String username = scan.next();

        try ( Connection connection = DBUtil.getConnection()){
            String sql = "DELETE FROM userinfo " +
                    "WHERE username = ?";
            PreparedStatement st = connection.prepareStatement(sql);
             st.setString(1, username);
             int count = st.executeUpdate();
             System.out.println(count > 0 ? "删除成功" : "删除失败");

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
